package com.txf.coomon.app;

import android.app.Application;
import android.content.Context;

import com.squareup.leakcanary.LeakCanary;
import com.squareup.leakcanary.RefWatcher;
import com.txf.other_toolslibrary.manager.ActivityLifecycleAdapter;
import com.txf.other_toolslibrary.tools.PreferenceTools;
import com.txf.other_toolslibrary.utils.ToastUtils;

/**
 * @author txf
 * @create 2019/1/30 0030
 * @
 */
public class MyApp extends Application {
    public static Context context;
    private RefWatcher refWatcher;

    @Override
    public void onCreate() {
        super.onCreate();
        this.context = this;
        initActvityManage();
        initLocal();
        initThird();
    }

    private void initActvityManage() {
        registerActivityLifecycleCallbacks(new ActivityLifecycleAdapter());
    }

    private void initLocal() {
        ToastUtils.init(this);
        PreferenceTools.getInstance().init(this);
    }

    private void initThird() {
        refWatcher = LeakCanary.install(this);
    }

    public static Context getContext() {
        return context;
    }

    public static RefWatcher getRefWatcher(Context context) {
        MyApp application = (MyApp) context.getApplicationContext();
        return application.refWatcher;
    }
}
